|
|
|
|
|
|
|
The program rotates points in the input image around the image's center. It translates the result so that it is centered in the output image. |
|
|
|
|
|
|
|
|
Figure 7.18 shows how to rotate the point (x, y) around the origin through the angle f. The distance R from (cx, cy) to (x, y) is: |
|
|
|
 |
|
|
|
|
R = Sqr(dx * dx + dy * dy) |
|
|
|
|
|
|
|
|
Using the arctangent function, the program can calculate the angle q = arctan(y/x). Unfortunately, Visual Basic's arctangent function Atn returns only values between p/2 and p/2. The ATan2 function shown in the following code uses Atn to return values for angles that fall outside this range. |
|
|
|
 |
|
|
|
|
' Return the arctan of dy/dx. Public Function ATan2( _
ByVal dy As Single, ByVal dx As Single) As Single
Const PI = 3.14159265
Dim theta As Single
If Abs(dx) < 0.01 Then
If dy < 0 Then
theta = -PI / 2
Else
theta = PI / 2
End If
Else
theta = Atn(dy / dx)
If dx < 0 Then theta = PI + theta
End If
ATan2 = theta
End Function |
|
|
|
|
|
|
|
|
Figure 7.18
Rotating a point through the angle f. |
|
|
|
|
|